﻿//全选/全不选
function selectAllNode(rootNode, checked) {
    rootNode.eachChild(function (child) {
        child.ui.toggleCheck(checked);
        child.attributes.checked = checked;
        child.fireEvent('checkchange', child, checked);
    });
}

//选择父节点,自动选中所有的子节点
function selectChildNode(node, checked) {
    node.expand();
    node.attributes.checked = checked;
    node.eachChild(function (child) {
        child.ui.toggleCheck(checked);
        child.attributes.checked = checked;
        child.fireEvent('checkchange', child, checked);
    });
}

//选择子节点,自动选中父节点的父节点
function selectParentNode(node, checked) {
    if (checked) {
        node.expand();
        var parentNode = node.parentNode;
        if (parentNode) {
            parentNode.attributes.checked = checked;
            var cb = parentNode.ui.checkbox;
            if (cb) cb.checked = checked;
            selectParentNode(parentNode, checked);
        }
    }
}